package com.spzx.product.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "分类品牌接口管理")
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {

    //调用Service层
    @Autowired
    private CategoryBrandService categoryBrandService;

    @Operation(summary = "查询分页分类品牌列表")
    @GetMapping("/list")
    public TableDataInfo list(CategoryBrand categoryBrand){
        //设置分页参数
        startPage();
        //调用Service
        List<CategoryBrand> list = categoryBrandService.selectCategoryBrandList(categoryBrand);
        //返回结果
        TableDataInfo dataInfo = getDataTable(list);
        return  dataInfo;
    }

    /**
     * 获取分类品牌详细信息
     */
    @Operation(summary = "获取分类品牌详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(categoryBrandService.selectCategoryBrandById(id));
    }

    //根据分类ID获取对应品牌数据
    @Operation(summary = "根据分类ID获取对应品牌数据")
    @GetMapping("brandList/{categoryId}")
    public AjaxResult selectBrandListByCategoryId(@PathVariable Long categoryId){
        return success(categoryBrandService.selectBrandListByCategoryId(categoryId));
    }


}
